package com.ruoyi.web.controller.biz;

import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.valid.ValidInsertGroup;
import com.ruoyi.common.valid.ValidUpdateGroup;
import com.ruoyi.system.domain.BsKefuCenter;
import com.ruoyi.system.service.BsKefuCenterService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @ClassName BsKefuCenterController
 * @Author kenn
 * @Version 1.0.0
 * @Date 2023年10月20日 09:46:00
 */
@RestController
@RequestMapping("/bs/kefu/center")
@Api(tags = "客服中心")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class BsKefuCenterController {

    private final BsKefuCenterService kefuCenterService;

    @GetMapping("/page/list")
    @ApiOperation("分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "question", value = "问题"),
            @ApiImplicitParam(name = "type", value = "问题类型 1：猜你想问 2：预约须知"),
            @ApiImplicitParam(name = "pageNum", value = "分页参数：第几页"),
            @ApiImplicitParam(name = "pageSize", value = "分页参数：每页条数"),
    })
    public Result<TableDataInfo<BsKefuCenter>> pageList(String question, String type) {
        PageDomain pageDomain = TableSupport.getPageDomain();
        return Result.success(kefuCenterService.pageList(pageDomain, question, type));
    }

    @PostMapping("/save")
    @ApiOperation("新增")
    public Result<?> save(@Validated(value = {ValidInsertGroup.class}) @RequestBody BsKefuCenter kefuCenter) {
        boolean save = kefuCenterService.saveEntity(kefuCenter);
        return save ? Result.success("新增成功") : Result.error("新增失败");
    }

    @PutMapping("/update")
    @ApiOperation("编辑")
    public Result<?> update(@Validated(value = {ValidUpdateGroup.class}) @RequestBody BsKefuCenter kefuCenter) {
        boolean save = kefuCenterService.updateEntity(kefuCenter);
        return save ? Result.success("编辑成功") : Result.error("编辑失败");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除")
    public Result<?> delete(@ApiParam("主键id") @PathVariable("id") Long id) {
        boolean remove = kefuCenterService.delete(id);
        return remove ? Result.success("删除成功") : Result.error("删除失败");
    }

    @GetMapping("/click")
    @ApiOperation("点击问题传-用于热搜排序")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id"),
    })
    public Result<BsKefuCenter> click(Long id) {
        return Result.success(kefuCenterService.click(id));
    }

}
